home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 20 code / Scripting the Finder / Zawphing / WindowHandler.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-11  |  2.7 KB  |  102 lines  |  [TEXT/MMCC]

  1. #ifndef __WINDOWHANDLER__
  2. #define __WINDOWHANDLER__
  3.  
  4. #include <Windows.h>
  5. #include <Events.h>
  6. #include "Exceptions.h"
  7.  
  8. #define kMagicWindowHandlerID            'whid'
  9.  
  10. #define eNoWindowHandler                -31113
  11.  
  12. //
  13. // Place an instance of this class in the RefCon of a toolbox window
  14. // to handle window events.  Create a derived class to customize
  15. // the event handling (which, by default, does nothing).
  16. //
  17. class TWindowHandler
  18. {
  19. protected:
  20.     long                fMagicWindowHandlerID;
  21.     WindowPtr            fWindow;
  22.  
  23. public:
  24.                         TWindowHandler() : fMagicWindowHandlerID(kMagicWindowHandlerID), fWindow(nil) {};
  25.     virtual                ~TWindowHandler();
  26.     void                IWindowHandler(WindowPtr window);
  27.     
  28.     Boolean                IsValidHandler() { return fMagicWindowHandlerID == kMagicWindowHandlerID; }
  29.     WindowPtr            ToolboxWindow() { Require(fWindow != nil); return fWindow; }
  30.     Rect*                PortRect() { return &(((WindowPeek)ToolboxWindow())->port.portRect); }
  31.     
  32.     //
  33.     // Toolbox event handling
  34.     //
  35.     virtual void        Idle(EventRecord* event);
  36.     virtual Boolean        KeyDown(EventRecord* event, char keyPressed);
  37.     virtual void        Update(EventRecord* event);
  38.     virtual void        Activate(EventRecord* event);
  39.     virtual void        Deactivate(EventRecord* event);
  40.     virtual void        Resume(EventRecord* event);
  41.     virtual void        Suspend(EventRecord* event);
  42.     
  43.     //
  44.     // Other event handling
  45.     //
  46.     virtual Boolean        ContentClick(EventRecord* event);
  47.     virtual void        ResizeWindow(Point where);
  48.     virtual void        CloseAndDelete();
  49.     virtual void        CloseWindowByUser();
  50.  
  51.     //
  52.     // Set the shape of the cursor:
  53.     //
  54.     virtual Boolean        SetupCursorShape(Point localMousePoint, RgnHandle localMouseRgn);
  55.     
  56.     //
  57.     // Menu handling
  58.     //
  59.     virtual void        SetupMenus();
  60.     virtual Boolean        ProcessMenuSelection(short commandID);
  61.         
  62.     //
  63.     // Modeless-dialog event handling (not applicable to windows that are not
  64.     // modeless dialog boxes)
  65.     //
  66.     virtual void        DialogManagerEvent(EventRecord* event, short itemHit);
  67. };
  68.  
  69. //
  70. // Modeless dialog boxes will set the cursor shape to an I-beam
  71. // when it is over a TextEdit object
  72. //
  73. // (Handle cut-copy-paste too?)
  74. //
  75. class TModelessDialogHandler : public TWindowHandler
  76. {
  77. public:
  78.                         TModelessDialogHandler() {};
  79.     virtual                ~TModelessDialogHandler();
  80.     void                IModelessDialogHandler(DialogPtr dialog);
  81.     
  82.     DialogPtr            DialogBoxPtr() { return (DialogPtr)fWindow; }
  83.                 
  84.     virtual Boolean        KeyDown(EventRecord* event, char keyPressed);
  85.     virtual Boolean        ContentClick(EventRecord* event);
  86.  
  87.     virtual void        CloseAndDelete();
  88.     virtual Boolean        SetupCursorShape(Point localMousePoint, RgnHandle localMouseRgn);
  89. };
  90.  
  91. //
  92. // Safe method for extracting a window handler from the refCon of a window
  93. //
  94. TWindowHandler* GetWindowHandler(WindowPtr window);
  95.  
  96. inline TWindowHandler* FrontWindowHandler()
  97. {
  98.     return GetWindowHandler(FrontWindow());
  99. }
  100.  
  101. #endif
  102.